package com.situ.crm.controller;


import com.situ.crm.entity.User;
import com.situ.crm.service.IUserService;
import com.situ.crm.util.JSONResult;
import com.situ.crm.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gao
 * @since 2021-11-03
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/getUserListPage")
    public String getUserListPage() {
        return "user/user_list";
    }

    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(Long page, Long limit) {
        return userService.selectByPage(page, limit);
    }

    @RequestMapping("/getUserInsertPage")
    public String getUserInsertPage() {
        return "user/user_insert";
    }

    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(User user, String roles) {
        userService.insert(user, roles);
        return JSONResult.ok("插入成功");
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public JSONResult deleteById(Integer id) {
        userService.deleteById(id);
        return JSONResult.ok("删除成功");
    }

    @RequestMapping("/getUserUpdatePage")
    public String getUserUpdatePage() {
        return "user/user_update";
    }

    @RequestMapping("/selectUserAndRoles")
    @ResponseBody
    public JSONResult selectUserAndRoles(Integer userId) {
        Map<String, Object> map = userService.selectUserAndRoles(userId);
        return JSONResult.ok(map);
    }

    @RequestMapping("/update")
    @ResponseBody
    public JSONResult update(User user, String roles) {
        userService.update(user, roles);
        return JSONResult.ok("插入成功");
    }
}

